******************************************************************************************************
******************************************************************************************************
//-----------------------------DEMOCRACY AND MASS SKEPTICISM OF SCIENCE-----------------------------//
//-------------------------------------  WORLD POLITICS  -------------------------------------------//
//------------------------------ For Replication and Publication -----------------------------------//
//---------------------------- (PISA & Olympiad Table A.17 - A.18) ---------------------------------//
******************************************************************************************************
******************************************************************************************************
//---------------NOTES---------------//
** Author: Junyan Jiang, Kin-Man Wan
** Last Updated: 
** Environment: 
*** Stata 17 SE
*** Windows 11 x64, AMD Ryzen 7 4800HS
*** 16GB RAM

//---------------TABLE A.17: Democracy and Student Performance in Science and Mathematics ---------------//
use "DATA_WP_jiang_wan_pisa",clear


eststo clear
eststo m1: reghdfe pisa_sci demo  logpop loggdppc, a(year) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum pisa_sci if e(sample)
estadd scalar dm = `r(mean)'

eststo m2: reghdfe pisa_sci e_polity2  logpop loggdppc, a(year) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum pisa_sci if e(sample)
estadd scalar dm = `r(mean)'

eststo m3: reghdfe pisa_sci v2x_polyarchy  logpop loggdppc, a(year) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum pisa_sci if e(sample)
estadd scalar dm = `r(mean)'


eststo m4: reghdfe pisa_math demo  logpop loggdppc, a(year) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum pisa_math if e(sample)
estadd scalar dm = `r(mean)'

eststo m5: reghdfe pisa_math e_polity2  logpop loggdppc, a(year) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum pisa_math if e(sample)
estadd scalar dm = `r(mean)'

eststo m6: reghdfe pisa_math v2x_polyarchy  logpop loggdppc, a(year) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum pisa_math if e(sample)
estadd scalar dm = `r(mean)'

esttab m*  using out.txt, nonote nobaselevels nogap keep(demo e_polity2 v2x_polyarchy) b(3) se(3) ///
order(demo e_polity2 v2x_polyarchy  ) star(+ 0.1 * 0.05 ** 0.01) label booktabs replace   nomtitles ///
mgroup("Science Performance" "Math Performance"  , pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats( dm  ctrl r2_a  N, labels("Dependent variable mean" "Control variables"  "Adjusted R$^2$"  "Observations") fmt(1 0  2 0 ) )


//---------------TABLE A.18: Democracy and Performance in International Mathematical Olympiad ---------------//
use "DATA_WP_jiang_wan_olympia", clear

eststo clear
eststo m1: reghdfe g_member demo logpop loggdppc   ,a(year  iso3 ) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum g_member if e(sample)
estadd scalar dm = `r(mean)'

eststo m2: reghdfe g_member e_polity2 logpop loggdppc   ,a(year  iso3 ) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum g_member if e(sample)
estadd scalar dm = `r(mean)'

eststo m3: reghdfe g_member v2x_polyarchy logpop loggdppc   ,a(year  iso3 ) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum g_member if e(sample)
estadd scalar dm = `r(mean)'


eststo m4: reghdfe medal_member demo logpop loggdppc   ,a(year  iso3 ) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum medal_member if e(sample)
estadd scalar dm = `r(mean)'

eststo m5: reghdfe medal_member e_polity2 logpop loggdppc   ,a(year  iso3 ) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum medal_member if e(sample)
estadd scalar dm = `r(mean)'

eststo m6: reghdfe medal_member v2x_polyarchy logpop loggdppc   ,a(year  iso3 ) cluster(iso3)
estadd local ctrl "$\checkmark$"
sum medal_member if e(sample)
estadd scalar dm = `r(mean)'

esttab m*  using out.txt, nonote nobaselevels nogap keep(demo e_polity2 v2x_polyarchy) b(3) se(3) ///
order(demo e_polity2 v2x_polyarchy  ) star(+ 0.1 * 0.05 ** 0.01) label booktabs replace   nomtitles ///
mgroup("\% of Gold Medals in Team" "\% of All Medals in Team"  , pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
stats( dm  ctrl r2_a  N, labels("Dependent variable mean" "Control variables"  "Adjusted R$^2$"  "Observations") fmt(1 0  2 0 ) )




